<?php

class Login_LoginController extends Zend_Controller_Action {

    public function indexAction() {
        $username = $_POST['username'];
        $password = $_POST['password'];

        $auth = new Zend_Auth_Adapter_Simple($username, $password);
        $instance = Zend_Auth::getInstance();
        $result = $instance->authenticate($auth);
        
        if ($result->isValid()) {
            $instance->getStorage()->write(array(
                'auth' => true,
                'id' => $result->getIdentity(),
                'acl' => 'administrador'
            ));
            return $this->_helper->redirector('index','dashboard', 'dashboard');
        }else{
            return $this->_helper->redirector('erro', 'index','');
        }
    }
    
    public function logoutAction(){
        $instance = Zend_Auth::getInstance();
        $instance->clearIdentity();
        $instance->getStorage()->clear();
        
        $sessioAcl = new Zend_Session_Namespace('acl');
        $sessioAcl->unsetAll();
        
        $sessioModulos = new Zend_Session_Namespace('modulos');
        $sessioModulos->unsetAll();
        
        return $this->_helper->redirector('index', '','');
    }
}